package xj.graph2d.template.uml;

import xj.graph2d.AbstractModelListener;
import xj.graph2d.DrawShape;
import xj.graph2d.GraphNodeBase;
import xj.graph2d.Label;
import xj.model.uml.UMLInterface;

public class UMLInterfaceModelListener extends AbstractModelListener {

  public UMLInterfaceModelListener() {
  }

  public UMLInterfaceModelListener(Object model, DrawShape shape) {
    super(model, shape);
  }

  @Override
  public void updateModel() {
    if (shape instanceof GraphNodeBase && model instanceof UMLInterface) {
      GraphNodeBase inode = (GraphNodeBase) shape;
      UMLInterface imodel = (UMLInterface) model;
      String name = inode.getLabel();
      if (name != null) {
	imodel.setName(name);
      }
    }
  }

  @Override
  public void updateShape() {
    if (shape instanceof GraphNodeBase && model instanceof UMLInterface) {
      GraphNodeBase inode = (GraphNodeBase) shape;
      UMLInterface imodel = (UMLInterface) model;
      String name = imodel.getName();
      if (name != null) {
	inode.setLabel(name);
	Label label = inode.getLabelShape();
	label.setDetachable(false);
	label.setDisplayName("Name");
      }
    }
  }

}
